package DB;


import Entity.Category;

/**this class asks queries to get and insert category's details from and into the db */
public class CategoryQuery {

	/**function which get type id from db */
	public static String getCategoryDB(String typeID) 
	{
		return "SELECT * FROM categories WHERE TypeID = " + "\"" + typeID +"\"";	
	}

	/**function which get type name from db */
	public static String getTypeNameDB(String typeName) 
	{
		return "SELECT * FROM categories WHERE TypeName = " + "\"" + typeName +"\"";
	}
	
	/**function which get category name from db */
	public static String getCategoryNameDB(String typeName, String CategoryName) 
	{
		return "SELECT * FROM categories WHERE TypeName = " + "\"" + typeName +"\" AND TypeCategories =" + "\"" + CategoryName +"\"";
	}

	/**function which get product's details from db*/
	public static String getProductDB( String productID) 
	{
		/**Prepare queries*/
		String str = "SELECT * FROM products WHERE ProductID = " + "\"" + productID + "\"";
		return str;
	}
	
	/**function which insert category's details into category's db   */
	public static String setCategoryDB(Category ctg)
	{
		if (ctg.getCategoryName()=="") /**category name is empty*/
		{
			return  "INSERT INTO categories (TypeID , TypeCategories) VALUES ("
					+ ctg.getTypeId()
					+ ",\""
					+ ctg.getTypeName()
					+ "\")";
		}
		else
		{
			return  "INSERT INTO categories (TypeID , TypeName, TypeCategories) VALUES ("
					+ ctg.getTypeId()
					+ ",\""
					+ ctg.getTypeName()
					+ "\",\""
					+ ctg.getCategoryName()
					+ "\")";

		}
	}

	/**function which insert category's details into category_product's db   */
	public static String setCategory_productDB(Category ctg)
	{
		return  "INSERT INTO category_product (CategoryID , ProductID) VALUES ("
				+ ctg.getTypeId()
				+ ",\""
				+ ctg.getProductID()
				+ "\")";

	}

	/**functions which check if a field is empty */
	public  boolean isEmpty(String field) 
	{
		if (field.isEmpty())
			return true;
		return false;
	}

	public  boolean isEmpty(int field) 
	{
		if (field!=0)
			return true;
		return false;
	}

}
